package com.edu.exam.enums.examination;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 安排任务类型枚举
 * 管理考试自动安排任务的类型分类
 *
 * @author System
 * @version 1.0.0
 */
public enum ArrangementTaskType implements BaseEnum {

    BATCH_ARRANGEMENT("BATCH_ARRANGEMENT", "批量安排", 1),
    SINGLE_ARRANGEMENT("SINGLE_ARRANGEMENT", "单个安排", 2),
    OPTIMIZATION("OPTIMIZATION", "优化调整", 3),
    RE_ARRANGEMENT("RE_ARRANGEMENT", "重新安排", 4),
    VALIDATION("VALIDATION", "验证检查", 5);

    private final String code;
    private final String description;
    private final int order;

    ArrangementTaskType(String code, String description, int order) {
        this.code = code;
        this.description = description;
        this.order = order;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    public int getOrder() {
        return order;
    }

    /**
     * 根据编码查找枚举值
     *
     * @param code 业务编码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果编码无效
     */
    public static ArrangementTaskType fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            throw new IllegalArgumentException("Arrangement task type code cannot be null or empty");
        }

        for (ArrangementTaskType value : values()) {
            if (value.getCode().equals(code)) {
                return value;
            }
        }
        throw new IllegalArgumentException("Unknown arrangement task type code: " + code);
    }

    /**
     * 根据描述查找枚举值
     *
     * @param description 显示描述
     * @return 对应的枚举值，null如果未找到
     */
    public static ArrangementTaskType fromDescription(String description) {
        for (ArrangementTaskType value : values()) {
            if (value.getDescription().equals(description)) {
                return value;
            }
        }
        return null;
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}
